import {Controller, Get, Render, UseBefore, Session} from "routing-controllers";
import { CheckLoginMiddleware } from "../../middleware/CheckLoginMiddleware";
import { utils } from "../../utils/utils";
import { Service, Inject } from "typedi";
import { CarServiceImpl } from "../../service/impl/CarServiceImpl";

@Service()
@Controller("/my")
@UseBefore(CheckLoginMiddleware)
export class MemberControllerHome {
	
	@Inject()
	private carServiceImpl: CarServiceImpl;
	
	@Get("/")
	@Render("home/member/welcome")
	public async welcome (@Session() session) {
		return {
			title: utils.titleName("个人中心"),
			isShowAction: {
				header: true,
				footer: true
			},
			banner: {
				bannerTitle: '个人中心',
				bannerUrl: '/img/banner_6.jpg',
			},
			login: session.user ? session.user : false
		}
	}

	@Get("/base")
	@Render("home/member/base")
	public async index (@Session() session) {
		console.log(session.user)
		return {
			title: utils.titleName("资料修改"),
			isShowAction: {
				header: true,
				footer: true
			},
			banner: {
				bannerTitle: '资料修改',
				bannerUrl: '/img/banner_6.jpg',
			},
			login: session.user ? session.user : false,
			userInfo: session.user ? session.user : {}
		}
	}

	@Get("/cp")
	@Render("home/member/changePassword")
	public async changePassword (@Session() session) {
		return {
			title: utils.titleName("账号密码"),
			isShowAction: {
				header: true,
				footer: true
			},
			banner: {
				bannerTitle: '账号密码',
				bannerUrl: '/img/banner_6.jpg',
			},
			login: session.user ? session.user : false
		}
	}
	
	@Get("/paycourse")
	@Render("home/member/paycourse")
	public async PurchasedCourses (@Session() session) {
		return {
			title: utils.titleName("已购买课程"),
			isShowAction: {
				header: true,
				footer: true
			},
			banner: {
				bannerTitle: '已购买课程',
				bannerUrl: '/img/banner_6.jpg',
			},
			login: session.user ? session.user : false,
			courseList: await this.carServiceImpl.getCarPayList(session.user.objectId)
		}
	}
	
}